package cn.itrip.service;

import cn.itrip.beans.pojo.ItripUser;
import cn.itrip.dao.user.ItripUserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author jie
 * @date 2019/5/7 -10:01
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private ItripUserMapper userMapper;

    @Override
    public ItripUser login(String username, String pwd) throws Exception {
        ItripUser user = findByUserCode(username);
        if(user!=null && user.getUserPassword().equals(pwd)){
            return user;
        }
        return null;
    }

    @Override
    public ItripUser findByUserCode(String userCode) throws Exception {
        Map<String,Object> param = new HashMap<>();
        param.put("userCode",userCode);
        List<ItripUser> itripUserListByMap = userMapper.getItripUserListByMap(param);
        if(itripUserListByMap.size()!=0){
           return itripUserListByMap.get(0);
        }
        return null;
    }

    @Override
    public Integer addUser(ItripUser user) throws Exception {

        return userMapper.insertItripUser(user);
    }
}
